package com.lujianfei.virusbroadcast.factory;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.lujianfei.lib.utils.ScreenUtils;
import com.lujianfei.virusbroadcast.Constants;
import com.lujianfei.virusbroadcast.beans.City;
import com.lujianfei.virusbroadcast.beans.Person;
import com.lujianfei.virusbroadcast.beans.Person.State;
import com.lujianfei.virusbroadcast.cache.SPRepository;

/**
 * 区域人群对象池
 *
 * @ClassName: PersonPool
 * @Description: 区域人群对象池，该地区假设为一个近似封闭的环境，拥有几乎不变的民众数量
 * @author: Bruce Young
 * @date: 2020年02月02日 17:21
 */
public class PersonPool {
    private static PersonPool personPool = new PersonPool();

    public static PersonPool getInstance() {
        return personPool;
    }

    List<Person> personList = new ArrayList<Person>();

    public List<Person> getPersonList() {
        return personList;
    }


    /**
     * 获取各类人群人数
     * @return 获取指定人群数量
     */
    public PersonCount getPeopleSize() {
    	PersonCount personCount = new PersonCount();
        for (Person person : personList) {
            if (person.getState() == State.NORMAL) {
            	++personCount.normalCount;
            }
            if (person.getState() == State.CONFIRMED) {
            	++personCount.confirmedCount;
            }
            if (person.getState() == State.DEATH) {
            	++personCount.deathCount;
            }
            if (person.getState() == State.FREEZE) {
            	++personCount.freezeCount;
            }
            if (person.getState() == State.SHADOW) {
            	++personCount.shadowCount;
            }
            if (person.getState() == State.SUSPECTED) {
            	++personCount.suspectedCount;
            }
        }
        return personCount;
    }
    

    private PersonPool() {
    	reset();
    }
    
    public void reset() {
    	personList.clear();
    	final int width = Constants.CITY_WIDTH - 300;
        City city = new City(width / 2, Constants.CITY_HEIGHT / 2);//设置城市中心为坐标(400,400)
        //添加城市居民
        for (int i = 0; i < SPRepository.getInstance().getCityPersonSize(); i++) {
            Random random = new Random();
            //产生N(a,b)的数：Math.sqrt(b)*random.nextGaussian()+a
            int x = (int) (100 * random.nextGaussian() + city.getCenterX());
            int y = (int) (100 * random.nextGaussian() + city.getCenterY());
            if (x > width) {
                x = width;
            }
            personList.add(new Person(city, x, y));
        }
    }
    
    public static class PersonCount {
    	public int getAllCount() {
			return allCount;
		}
		public void setAllCount(int allCount) {
			this.allCount = allCount;
		}
		public int getNormalCount() {
			return normalCount;
		}
		public void setNormalCount(int normalCount) {
			this.normalCount = normalCount;
		}
		public int getSuspectedCount() {
			return suspectedCount;
		}
		public void setSuspectedCount(int suspectedCount) {
			this.suspectedCount = suspectedCount;
		}
		public int getShadowCount() {
			return shadowCount;
		}
		public void setShadowCount(int shadowCount) {
			this.shadowCount = shadowCount;
		}
		public int getConfirmedCount() {
			return confirmedCount;
		}
		public void setConfirmedCount(int confirmedCount) {
			this.confirmedCount = confirmedCount;
		}
		public int getFreezeCount() {
			return freezeCount;
		}
		public void setFreezeCount(int freezeCount) {
			this.freezeCount = freezeCount;
		}
		public int getDeathCount() {
			return deathCount;
		}
		public void setDeathCount(int deathCount) {
			this.deathCount = deathCount;
		}
		int allCount = 0;
		int normalCount = 0;
    	int suspectedCount = 0;
    	int shadowCount = 0;
    	int confirmedCount = 0;
    	int freezeCount = 0;
    	int deathCount = 0;
    }
}
